/**
 * 2016，thor.com，all rights reserved。
 * 
 * Project：		palmmall-core
 * Filename：	SComplaintConverter.java
 * Created：		2016年8月21日
 * Creator：		wolv
 */
package com.thor.palmmall.rest.repair.converter;

import java.util.ArrayList;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.UCN;
import com.thor.commons.util.ConverterUtil;
import com.thor.palmmall.rest.common.ASubjectWithDirectionConverter;
import com.thor.palmmall.rest.common.SSubjectWithDirectionConverter;
import com.thor.palmmall.rest.repair.ARepairRecord;
import com.thor.palmmall.spi.maintain.SRepairRecord;

/**
 * @author wolv
 *
 */
public class SRepairRecordConverter implements Converter<ARepairRecord, SRepairRecord> {

  public static SRepairRecordConverter getInstance() {
    if (instance == null)
      instance = new SRepairRecordConverter();
    return instance;
  }

  private static SRepairRecordConverter instance;

  private SRepairRecordConverter() {
  }

  @Override
  public SRepairRecord convert(ARepairRecord source) {
    if (source == null)
      return null;

    SRepairRecord target = new SRepairRecord();
    target.setArtificialFeeCharge(source.isArtificialFeeCharge());
    target.setMaterialFeeCharge(source.isMaterialFeeCharge());
    target.setPartsFeeCharge(source.isPartsFeeCharge());
    target.setArtificialFee(source.getArtificialFee());
    target.setPartsFee(source.getPartsFee());
    target.setArtificalSubject(
        SSubjectWithDirectionConverter.getInstance().convert(source.getArtificalSubject()));
    target.setPartsSubject(
        SSubjectWithDirectionConverter.getInstance().convert(source.getPartsSubject()));
    target.setFeeRecords(
        ConverterUtil.convert(source.getFeeRecords(), SFeeRecordConverter.getInstance()));
    target.setProcesses(
        ConverterUtil.convert(source.getProcesses(), SProcessRecordConverter.getInstance()));
    target.setServicemans(new ArrayList<UCN>());
    if (source.getServicemans() != null)
      for (UCN sourceServiceman : source.getServicemans())
        target.getServicemans().add(UCN.newInstance(sourceServiceman));
    return target;
  }
}
